package Exam2;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        try {
            Map<Integer, Integer> map = new HashMap<>();
            int index = 1;
            while (map.size() < 100) {
                int num = (int) (Math.random() * 200) + 1;
                map.put(num, index++);
            }

            while (map.size() > 1) {
                Set<Map.Entry<Integer, Integer>> set = map.entrySet();
                Iterator<Map.Entry<Integer, Integer>> iterator = set.iterator();
                while (iterator.hasNext()) {
                    Map.Entry<Integer,Integer> entry = iterator.next();
                    Integer key = entry.getKey();
                    Integer value = entry.getValue();
                    if (value % 2 == 1 && map.size() > 1) {
                        iterator.remove();
                    } else {
                        entry.setValue(value / 2);
                    }
                }
            }
            System.out.println(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
